package com.example.demo.controller;

import com.example.demo.handler.MyWebSocketHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
public class WebSocketController {

    @Autowired
    private MyWebSocketHandler myWebSocketHandler;

    @GetMapping("/push")
    public String pushMessage(String message) {
        try {
            // 推送消息给所有客户端
            myWebSocketHandler.broadcast(message);
            return "消息已推送: " + message;
        } catch (Exception e) {
            return "推送失败";
        }
    }
}
